//index.js
//获取应用实例
const app = getApp()
var request = require('../../utils/request.js');

Page({
  data: {
    username: '',
    password: ''
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onShow: function () {
    // 生命周期函数--监听页面显示
    wx.hideTabBar({})
  },
  onLoad: function () {

  },


  // 获取输入账号 
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value
    })
  },

  // 获取输入密码 
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },

  // 登录处理
  login: function () {
    var that = this;
    if (this.data.username.length == 0 || this.data.password.length == 0) {
      wx.showToast({
        title: '账号或密码不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      let d = {
        username: this.data.username,
        password: this.data.password
      }
      request.postData(
        "?type=login",
        JSON.stringify(d),
        (data) => {
          console.log(data);
          if (data.code == 200) {
            app.globalData.userInfo= data.data;
            wx.switchTab({
              url: '../home/home'
            })
          } else {
            wx.showToast({
              title: data.msg,
              icon: "none"
            })
          }

        },
        (err) => {

        }
      );
    }
  },
  goRegister:function(){
    wx.navigateTo({
      url: '/pages/register/register'
    })
  }
})
